#include "game.h"

void menu()
{
    printf("********************************\n");
    printf("*********    1.play     ********\n");
    printf("*********    0.exit     ********\n");
    printf("********************************\n");
}
void game()
{
    char ret = 0;
    //开始游戏1
    printf("游戏：三子棋\n");
    //创建放棋子的棋盘
    char board[ROW][COL] = { 0 };
    //初始化棋盘为空
    Initboard(board,ROW,COL);
    //打印棋盘
    Displayboard(board,ROW,COL);
    while(1)
    {
    //玩家下棋
    Player_move(board,ROW,COL);
    Displayboard(board,ROW,COL);
    //判断输赢
    ret = Is_win(board,ROW,COL);
    if(ret != 'c')
    {
        break;
    }
    //电脑下棋
    Computer_move(board,ROW,COL);
    Displayboard(board,ROW,COL);
    //判断输赢
    ret = Is_win(board,ROW,COL);
    if(ret != 'c')
    {
        break;
    }
    }
    if(ret == '*')
    {
        printf("玩家获胜\n");
        Displayboard(board,ROW,COL);

    }
    else if(ret == '#')
    {
        printf("电脑获胜\n");
        Displayboard(board,ROW,COL);    
    }
    else
    {
        printf("平局\n");
        Displayboard(board,ROW,COL);    
    }
}
int main()
{
    int input = 0;
    srand((unsigned int)time(NULL));
    do
    {
        menu();
        printf("请选择：>\n");
        scanf("%d",&input);
        switch(input)
        {
        case 1:
            game();
            break;
        case 0:
            printf("退出\n");
            break;
        default:
            printf("输入错误，请重新输入！\n");
            break;
        }
    } while (input);
    return 0;
}